//#define __DEBUG__
#define THIS_FILE "x_prio_4.sqf"
#include "x_setup.sqf"

__TRACE_1("_this","_this")

private ["_poss","_kind","_objs","_unit","_svec","_isFlat","_crew","_pos","_center_x","_center_y","_count_obj","_radius","_angle","_dir","_angle_plus","_bag"];
PARAMS_2(_poss,_kind);

_type = switch (GVAR(side_enemy)) do {
	case west: { "B_Truck_01_box_F" };
	case resistance: { "I_Truck_02_box_F" };
	default { "O_Truck_02_box_F" };
};

_objs = [];
_unit = createVehicle [_type, _poss, [], 0, "NONE"];
_svec = (sizeOf (typeOf _unit) max 1.5);
_isFlat = (position _unit) isFlatEmpty [_svec / 2, 150, 0.7, _svec, 0, false, _unit];
if (count _isFlat > 1) then {
	_isFlat set [2,0];
	if ((_poss distance _isFlat) < 50) then {
		_poss = _isFlat;
	};
};
_poss set[2,0];
_unit setPos _poss;
_unit lock 2;
_unit setFuel 0;
_unit setFuelCargo 0;
_unit setAmmoCargo 0;

_bag = createVehicle ["CamoNet_OPFOR_big_F",[0,0,0], [], 0, "CAN_COLLIDE"];
_bag allowDamage false;
_bag setPos _poss;
_bag allowDamage true;
_objs set [count _objs, _bag];


_center_x = (getPos _unit) select 0;
_center_y = (getPos _unit) select 1;
_radius = ((12 max _svec) min 14);
_angle = 45;
_count_obj = 4;
_angle_plus = 360 / _count_obj;
for "_i" from 0 to (_count_obj - 1) do {
	_x1 = _center_x - (_radius * sin _angle);
	_y1 = _center_y - (_radius * cos _angle);
	_pos = [_x1,_y1,0];
	_dir = (_angle + 180);
	_angle = _angle + _angle_plus;
	_bag = createVehicle ["Land_HBarrierWall6_F",_pos, [], 0, "CAN_COLLIDE"];
	_bag setDir _dir;
	_bag setPos _pos;
	_objs set [count _objs, _bag];
	
	_pos = _bag modelToWorld [7,0,0];
	_pos set [2,0];
	_bag = createVehicle ["Land_HBarrierWall6_F",_pos, [], 0, "CAN_COLLIDE"];
	_bag setDir _dir;
	_objs set [count _objs, _bag];
	
	_pos = _bag modelToWorld [-14,0,0];
	_pos set [2,0];
	_bag = createVehicle ["Land_HBarrierWall6_F",_pos, [], 0, "CAN_COLLIDE"];
	_bag setDir _dir;
	_objs set [count _objs, _bag];
};

_unit spawn {
	private ["_truck","_players","_center","_radius","_target_array2","_target","_drone","_type","_grp","_wp","_drone_radius","_flyInHeight","_timeout","_tg_pos", "_fnc_addGunner","_fnc_killed", "_fnc_setTarget"];
	_truck = _this;
	__TargetInfo
	_center = (_target_array2 select 0);
	_radius = ((_target_array2 select 2) * 2);
};

__TRACE_2("End","_unit","_objs");
[_unit,_objs]